
package upcoming.client;

import java.util.*;

public class VenueSearchCriteria implements java.io.Serializable
{
	private static final long serialVersionUID = 1L;

	private Double latitude;
	private Double longitude;
	private String location;
	private String searchText;
	private Integer radius;
	private String metroId;
	private String stateId;
	private String countryId;
	
	
	public void setLatLong(String latlong)
	{
		StringTokenizer tokenizer = new StringTokenizer(latlong, " \n\t,");
		while (tokenizer.hasMoreTokens())
		{
			setLatitude(Double.parseDouble(tokenizer.nextToken()));
			setLongitude(Double.parseDouble(tokenizer.nextToken()));
		}
		
	}
	
	public void setLatLong(double lat, double lon)
	{
		this.setLatitude(lat);
		this.setLongitude(lon);
	}
	
	public void setSearchText(String s)
	{
		this.searchText = s;
	}


	public boolean hasLatLong()
	{
		return ((this.latitude != null) && (this.longitude != null));
	}
	
	public String getLatLong()
	{
		if (hasLatLong())
		{
			return this.latitude + ", " + this.longitude;
		}
		else
		{
			throw new IllegalStateException("no lat/long");
		}
	}
	
	public Double getLatitude()
	{
		return latitude;
	}

	public void setLatitude(Double lat)
	{
		this.latitude = lat;
	}

	public Double getLongitude()
	{
		return longitude;
	}

	public void setLongitude(Double lon)
	{
		this.longitude = lon;
	}

	public String getSearchText()
	{
		return searchText;
	}

	public Map<String, String> toMap()
	{
		
		Map<String, String> m = new LinkedHashMap<String, String>();
		
		m.put("method", "venue.search");
		
		if (this.getCountryId() != null)
		{
			m.put("country_id", getCountryId());
		}
		
		if (this.getMetroId() != null)
		{
			m.put("metro_id", getMetroId());
		}

		if (this.getStateId() != null)
		{
			m.put("state_id", getMetroId());
		}
		
		if (this.getSearchText() != null)
		{
			m.put("search_text", this.getSearchText());
		}
		
		if (hasLatLong())
		{
			m.put("location", "\"" + this.getLatLong() + "\"");
		}
		else if (this.location != null)
		{
			m.put("location", "\"" + location + "\"");
		}
		
		
		if (this.getRadius() != null)
		{
			m.put("radius", this.getRadius().toString());
		}
		
		
		
		return m;
		
	}

	/**
	 * 
	 * @return radius in miles
	 * 
	 */
	public Integer getRadius()
	{
		return radius;
	}

	
	/*
	 * 
	 *  radius in miles
	 *  
	 */
	public void setRadius(int searchRadius)
	{
		if (searchRadius < 0)
		{
			this.radius = null;
		}
		else
		{
			this.radius = new Integer(searchRadius);
		}
	}


	public void setLocation(String loc)
	{
		location = loc;
	}

	public void setMetroId(String id)
	{
		this.metroId = id;
	}
	
	public String getMetroId()
	{
		return this.metroId;
	}

	public String getStateId()
	{
		return stateId;
	}

	public void setStateId(String id)
	{
		this.stateId = id;
	}

	public String getCountryId()
	{
		return countryId;
	}

	public void setCountryId(String id)
	{
		this.countryId = id;
	}
	

	
}
